package commands;

import enums.Weapon;
import nanoxml.XMLElement;
import utils.ITransmittable;

/**
 * This command represents a notification about which weapon the client
 * chose in case of a tie between players.
 */
public class CommandWeaponSelection implements ITransmittable
{
	private static final String ATTR_USER_NAME = "Username";
	private static final String ATTR_WEAPON = "Weapon";
	
	private String username = null; 
	private Weapon weapon = null;
	
	
	public CommandWeaponSelection(String username,Weapon weapon )
	{
		this.username = username;
		this.weapon = weapon;
	}
	public CommandWeaponSelection(XMLElement command)
	{
		this((String)command.getAttribute(ATTR_USER_NAME) ,   Weapon.getWeaponfromString((String)command.getAttribute(ATTR_WEAPON)) );	
	}

	@Override
	public XMLElement toXML()
	{
		XMLElement message  = new XMLElement();
		message.setName(Commands.WEAPON_SELECTION);
		message.setAttribute(ATTR_USER_NAME, username);
		message.setAttribute(ATTR_WEAPON, weapon.toString());
		return message;
	}
	
	public String getUsername()
	{
		return username;
	}
	public Weapon getWeapon() {
		return weapon;
	}
}